package com;

import com.dao.MessageDAO;
import com.domain.Message;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MessageService {
    @Resource
    private MessageDAO messageDAO;

    @Transactional(readOnly = true)
    public List<Message> getMessages() {
        return messageDAO.getMessages();
    }

    @Transactional
    public void addMessage(String msg, String nickname) {
        long time = System.currentTimeMillis();
        Message message = new Message();
        message.setChatterName(nickname);
        message.setTime(time);
        message.setMessage(msg);
        messageDAO.addMessage(message);
    }
}
